# -*- coding: utf-8 -*-
"""
@author:xuyuntao
@time:2021/2/8:10:59
@email:xuyuntao@189.cn
"""
import numpy
import numpy.fft as nfft
import matplotlib.pyplot as plt
import matplotlib.font_manager
import matplotlib
from Generator import DigitalModulationGenerator
from Tools import get_desktop
import time
import dec2bin
import mpl_toolkits.axisartist as axisartist
import os
import argparse
parser = argparse.ArgumentParser(description='控制性参数')
parser.add_argument('--ifSave', type=str, default="True")
args = parser.parse_args()
print(args)
"""绘制论文第二章所有插图，包括四种调制的时域波形、频谱图以及部分调制的星座图"""
# ----------------------------数据计算部分----------------------------
# ---绘图控制---
startT=time.time()
workPath=os.path.join(get_desktop(),"Paper_Pictures\\","Paper_Chapter_2_Fig\\")  # 保存文件路径，末尾必须有\\，且全部只出现\\
if os.path.isdir(workPath):
    pass
else:
    os.mkdir(workPath)
saveDPI=400    # 除星座图的保存文件dpi
fileType="svg"   # 除星座图外的保存文件格式
saveDPI_constel=400  # 星座图保存文件dpi
fileType_constel="svg"  # 星座图的保存文件格式
ifSave=eval(args.ifSave)   # 是否保存图像
ifShow=True  # 是否显示fig窗口
lineWidth=1   # 绘图线宽
dBAxis=False  # 是否以dB为轴单位
figSizeNum = 8  # 窗口大小基本量
figSizeNum2 = 18  # 窗口大小基本量
figSize = (figSizeNum, round(figSizeNum / 4 * 3))  # 窗口大小
figSize2 = (figSizeNum2, round(figSizeNum2 / 8 * 3))  # 窗口大小
fontSize = 21  # 其他字体大小
numberSize = 18  # 轴刻度字号
# titleY=-1.0
markerSize=90
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
# ---各调制阶数---
ask_order_1=4  # ask阶数
psk_order_1=4  # psk阶数1
psk_order_2=16  # psk阶数1
qam_order_1=4  # qam阶数
qam_order_2=16  # qam阶数

fsk_order_1=2  # fsk阶数
fsk_order_2=4  # fsk阶数
# ---码元数据---
bitsData_1=numpy.array([0,0,1,1,0,1,1,0,1,1,0,0,1,0,0,1])  # 基带码元1
bitsData_2 = numpy.random.randint(0, 2, 1024)  # 基带码元2
# bitsData_3 = numpy.random.randint(0, 2, 256)  # 基带码元3 星座图专用
maxQamOrder=max(qam_order_1,qam_order_2)
maxQamBinLen=round(numpy.log2(maxQamOrder))
bitsData_3 = numpy.zeros(maxQamOrder*maxQamBinLen)  # 基带码元3 星座图专用
for qamOrder in range(maxQamOrder):  # 为星座图创建专用比特，使用最少比特将所有星座点表示出来
    binNum=dec2bin.dec2bin(qamOrder)
    for charIndex in range(-1,-1-len(binNum),-1):
        bitsData_3[qamOrder * maxQamBinLen:(qamOrder + 1) * maxQamBinLen][charIndex]=int(binNum[charIndex])
# ---基础信号参数---
bytesRate_1 = 16      # 码元速率
bytesRate_2 = 4      # 码元速率
bytesRate_3 = 16      # 码元速率
carrierFreq_1 = 32    # 载波频率
carrierFreq_2 = 32    # 载波频率
carrierFreq_3 = 32    # 载波频率
sampleFreq_1 = 60*carrierFreq_1   # 采样速率，应取得比较高
sampleFreq_2 = 60*carrierFreq_2   # 采样速率，应取得比较高
sampleFreq_3 = 60*carrierFreq_3   # 采样速率，应取得比较高
fftNumTimes = 2   # fft计算倍数
# --fsk特数参数--
seperate_1 = 16  # fsk两频率相较载波的偏差
seperate_2 = 8  # fsk两频率相较载波的偏差
fsk_phase_continue = True  # 是否相位连续

# -----创建DMG类，调制信号类-----
DMG_1=DigitalModulationGenerator(bitsData_1,bytesRate_1,carrierFreq_1,sampleFreq_1)  # 实例化类1
DMG_2=DigitalModulationGenerator(bitsData_2,bytesRate_2,carrierFreq_2,sampleFreq_2)  # 实例化类2
DMG_3=DigitalModulationGenerator(bitsData_3,bytesRate_3,carrierFreq_3,sampleFreq_3)  # 实例化类3_星座图专用

def getFreqAxis(sampleFreq,sampleLen):
    """计算频率轴坐标"""
    freqDelta=sampleFreq/sampleLen
    sampleArange=numpy.arange(sampleLen)
    axis=freqDelta*sampleArange
    return axis

def drawFFT(axes,sampleFreq,valueAxis,zhFont,fftNumTimes=1,centerFreq=None,halfBand=None,dBAxis=False,lineWidth=1,fontSize=15):
    """绘制fft图"""
    fftPoints=round(valueAxis.size*fftNumTimes)
    freqAxis = getFreqAxis(sampleFreq, fftPoints)
    if dBAxis:
        axes.plot(freqAxis[:round(fftPoints / 2)],
                  numpy.log10(numpy.abs(nfft.fft(valueAxis,fftPoints))[:round(fftPoints / 2)]),linewidth=lineWidth)
    else:
        axes.plot(freqAxis[:round(fftPoints / 2)],
                  numpy.abs(nfft.fft(valueAxis,fftPoints))[:round(fftPoints / 2)],linewidth=lineWidth)
    axes.set_xlabel("频率 (Hz)",fontproperties=zhFont,fontsize=fontSize)
    # axes.set_ylabel("绝对值",fontproperties=zhFont)
    if dBAxis:
        axes.set_ylabel("对数值 (dB)",fontproperties=zhFont,fontsize=fontSize)
    else:
        axes.set_ylabel("绝对值", fontproperties=zhFont,fontsize=fontSize)
    if centerFreq==None:
        pass
    else:   # 按这个中心点画
        if halfBand==None:
            pass
        else:
            axes.set_xlim([centerFreq-halfBand,centerFreq+halfBand])
    return axes

def drawTimeDomain(axes,timeSeries,value,zhFont,lineWidth=1,fontSize=15):
    """绘制时域图"""
    axes.plot(timeSeries, value,linewidth=lineWidth)
    axes.set_xlabel("时间 (s)",fontproperties=zhFont,fontsize=fontSize)
    axes.set_ylabel("值", fontproperties=zhFont,fontsize=fontSize)
    return axes

def setConstelAxis(axes,numberSize,arrowSize=1.0):
    axes.axis[:].set_visible(False)  # 通过set_visible方法设置绘图区所有坐标轴隐藏
    axes.axis["x"] = axes.new_floating_axis(0, 0)  # ax.new_floating_axis代表添加新的坐标轴
    axes.axis["x"].set_axisline_style("->", size=arrowSize)  # 给x坐标轴加上箭头
    # 添加y坐标轴，且加上箭头
    axes.axis["y"] = axes.new_floating_axis(1, 0)
    axes.axis["y"].set_axisline_style("->", size=arrowSize)
    # 设置x、y轴上刻度显示方向
    axes.axis["x"].set_axis_direction("top")
    axes.axis["y"].set_axis_direction("right")
    axes.axis["x"].major_ticklabels.set_fontsize(numberSize)
    axes.axis["y"].major_ticklabels.set_fontsize(numberSize)
    return axes

def formatnum(x, pos):
    """转换y轴为科学计数法"""
    return '$%.1f$x$10^{4}$' % (x/10000)

def formatnum_pi(x, pos):
    """转换x轴为pi的倍数"""
    return '$%.2f \pi$' % (x/numpy.pi)

# --------------生成各种信号--------------
DMG_1_askSignal_1, DMG_1_askTimeSeries_1=DMG_1.getSignal_real("ask", ask_order_1, True)  # ask信号
DMG_1_askSignal_1_complex, DMG_1_askAbsTimeSeries_1=DMG_1.getSignal("ask", ask_order_1, True)  # ask信号
DMG_1_pskSignal_1, DMG_1_pskTimeSeries_1=DMG_1.getSignal_real("psk", psk_order_1, True)  # psk信号
DMG_1_pskSignal_2, DMG_1_pskTimeSeries_2=DMG_1.getSignal_real("psk", psk_order_2, True)  # psk信号
DMG_1_qamSignal_1_complex, DMG_1_qamTimeSeries_1=DMG_1.getSignal("qam", qam_order_1, True)  # qam信号
DMG_1_qamSignal_2_complex, DMG_1_qamTimeSeries_2=DMG_1.getSignal("qam", qam_order_2, True)  # qam信号
# DMG_1_qamBand_1_complex=DMG_1.modulate_qam(DMG_1._dataLengthValid(qam_order_1), qam_order_1)
# DMG_1_qamBand_2_complex=DMG_1.modulate_qam(DMG_1._dataLengthValid(qam_order_2), qam_order_2)
DMG_1_fskSignal_1, DMG_1_fskTimeSeries_1=DMG_1.getSignal_real("fsk", fsk_order_1, True, seperate_1, fsk_phase_continue)  # fsk信号
DMG_1_fskSignal_2, DMG_1_fskTimeSeries_2=DMG_1.getSignal_real("fsk", fsk_order_2, True, seperate_1, fsk_phase_continue)  # fsk信号

DMG_2_askSignal_1,DMG_2_askTimeSeries_1=DMG_2.getSignal_real("ask", ask_order_1, True)  # ask信号
DMG_2_pskSignal_1,DMG_2_pskTimeSeries_1=DMG_2.getSignal_real("psk", psk_order_1, True)  # psk信号
DMG_2_pskSignal_2,DMG_2_pskTimeSeries_2=DMG_2.getSignal_real("psk", psk_order_2, True)  # psk信号
DMG_2_qamSignal_1_complex,DMG_2_qamTimeSeries_1=DMG_2.getSignal("qam", qam_order_1, True)  # qam信号
DMG_2_qamSignal_2_complex,DMG_2_qamTimeSeries_2=DMG_2.getSignal("qam", qam_order_2, True)  # qam信号
# DMG_2_qamBand_1_complex=DMG_2.modulate_qam(DMG_2._dataLengthValid(qam_order_1),qam_order_1)
# DMG_2_qamBand_2_complex=DMG_2.modulate_qam(DMG_2._dataLengthValid(qam_order_2),qam_order_2)
DMG_2_fskSignal_1,DMG_2_fskTimeSeries_1=DMG_2.getSignal_real("fsk", fsk_order_1, True, seperate_2, fsk_phase_continue)  # fsk信号
DMG_2_fskSignal_2,DMG_2_fskTimeSeries_2=DMG_2.getSignal_real("fsk", fsk_order_2, True, seperate_2, fsk_phase_continue)  # fsk信号

DMG_3_pskBand_1_complex=DMG_3.getConstel("psk",psk_order_1,True)
DMG_3_pskBand_2_complex=DMG_3.getConstel("psk",psk_order_2,True)

DMG_3_qamBand_1_complex=DMG_3.getConstel("qam",qam_order_1,True)
DMG_3_qamBand_2_complex=DMG_3.getConstel("qam",qam_order_2,True)

DMG_3_askBand_1_complex=DMG_3.getConstel("ask",ask_order_1,True)

endT=time.time()
print("计算总共消耗时间:",endT-startT,"s")

# ----------------------------绘图部分----------------------------
figNum=1  # 窗口号缓存
zhFont=matplotlib.font_manager.FontProperties(fname='C:\Windows\Fonts\simsun.ttc')  # 中文字体
# --------------比特数据--------------
bitsDataFig=plt.figure(figNum, figsize=figSize)
figNum+=1
bitsDataAx=bitsDataFig.add_subplot(1,1,1)
bitsDataAx.plot(DMG_1.timeSeries[0:DMG_1.timeN],DMG_1.bitsData.repeat(DMG_1.NperBytes),linewidth=lineWidth)
bitsDataAx.tick_params(axis="both",labelsize=numberSize)
# bitsDataFig.suptitle("比特数据",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    bitsDataFig.savefig(workPath+str(figNum-1)+"_"+"bitsDataFig."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    bitsDataFig.show()
print("fig"+str(figNum-1)+":","比特数据")
# --------------ASK--------------
# 绘制：时域图、频域图
askFig_1=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域---
# askFig_time_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
askAx_time_1=askFig_1.add_subplot(1,2,1)
askAx_time_1=drawTimeDomain(askAx_time_1, DMG_1_askTimeSeries_1, DMG_1_askSignal_1, zhFont, lineWidth,fontSize)
askAx_time_1.tick_params(axis="both",labelsize=numberSize)
# askFig_time_1.suptitle(str(ask_order_1)+"ASK时域",y=titleY,fontproperties=zhFont,fontsize=fontSize)
# askAx_time_1.set_title(str(ask_order_1)+"ASK时域",y=titleY,fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     askFig_time_1.savefig(workPath+str(figNum-1)+"_"+"askFig_time_1."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     askFig_time_1.show()
print("fig"+str(figNum-1)+":",str(ask_order_1)+"ASK时域")
# ---频域---
# askFig_fft_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
askAx_fft_1=askFig_1.add_subplot(1,2,2)
askAx_fft_1=drawFFT(askAx_fft_1, sampleFreq_2, DMG_2_askSignal_1, zhFont, fftNumTimes, carrierFreq_2, 1.5 * bytesRate_2, dBAxis, lineWidth,fontSize)
askAx_fft_1.tick_params(axis="both",labelsize=numberSize)
askAx_fft_1.yaxis.get_major_formatter().set_powerlimits((0,3))
# askFig_fft_1.suptitle(str(ask_order_1)+"ASK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    askFig_1.savefig(workPath+str(figNum-1)+"_"+"askFig_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    askFig_1.show()
print("fig"+str(figNum-1)+":",str(ask_order_1)+"ASK频域")
# ---频域独立---
askFig_fft_1=plt.figure(figNum, figsize=figSize)
figNum+=1
askAx_fft_1_only=askFig_fft_1.add_subplot(1,1,1)
askAx_fft_1_only=drawFFT(askAx_fft_1_only, sampleFreq_2, DMG_2_askSignal_1, zhFont, fftNumTimes, carrierFreq_2, 1.5 * bytesRate_2, dBAxis, lineWidth,fontSize)
askAx_fft_1_only.tick_params(axis="both",labelsize=numberSize)
askAx_fft_1_only.yaxis.get_major_formatter().set_powerlimits((0,3))
# askFig_fft_1.suptitle(str(ask_order_1)+"ASK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    askFig_fft_1.savefig(workPath+str(figNum-1)+"_"+"askFig_fft_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    askFig_fft_1.show()
print("fig"+str(figNum-1)+":",str(ask_order_1)+"ASK频域 独立")
# ---包络---
askFig_abs_1=plt.figure(figNum, figsize=figSize)
figNum+=1
askAx_abs_1=askFig_abs_1.add_subplot(1,1,1)
askAx_abs_1.plot(DMG_1_askAbsTimeSeries_1, numpy.abs(DMG_1_askSignal_1_complex), linewidth=lineWidth)
askAx_abs_1.set_xlabel("时间 (s)", fontproperties=zhFont, fontsize=fontSize)
askAx_abs_1.set_ylabel("包络", fontproperties=zhFont, fontsize=fontSize)
askAx_abs_1.set_ylim([0,DMG_1_askSignal_1.max()])
askAx_abs_1.tick_params(axis="both",labelsize=numberSize)
# askAx_abs_1.set_title(str(ask_order_1)+"ASK包络",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    askFig_abs_1.savefig(workPath+str(figNum-1)+"_"+"askFig_abs_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    askFig_abs_1.show()
print("fig"+str(figNum-1)+":",str(ask_order_1)+"ASK包络")
# ---星座图1---
askFig_constel_1=plt.figure(figNum, figsize=figSize)
figNum+=1
askAx_constel_1= axisartist.Subplot(askFig_constel_1, 1,1,1)#askFig_constel_1.add_subplot(1,1,1)
askAx_constel_1=setConstelAxis(askAx_constel_1,numberSize)
askAx_constel_1.scatter(DMG_3_askBand_1_complex.real, DMG_3_askBand_1_complex.imag,s=markerSize)
askFig_constel_1.add_axes(askAx_constel_1)
# askAx_constel_1.tick_params(axis="both",labelsize=numberSize)
# askFig_constel_1.suptitle(str(ask_order_1)+"ASK星座图",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    askFig_constel_1.savefig(workPath+str(figNum-1)+"_"+"askFig_constel_1."+fileType_constel,dpi=saveDPI_constel,format=fileType_constel,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    askFig_constel_1.show()
print("fig"+str(figNum-1)+":",str(ask_order_1)+"ASK星座图")
# --------------PSK--------------
# 绘制：时域、频域
# ---PSK1---
pskFig_1=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域1---
# pskFig_time_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_time_1=pskFig_1.add_subplot(1,2,1)
pskAx_time_1=drawTimeDomain(pskAx_time_1, DMG_1_pskTimeSeries_1, DMG_1_pskSignal_1, zhFont, lineWidth,fontSize)
pskAx_time_1.tick_params(axis="both",labelsize=numberSize)
# pskFig_time_1.suptitle(str(psk_order_1)+"PSK时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     pskFig_time_1.savefig(workPath+str(figNum-1)+"_"+"pskFig_time_1."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     pskFig_time_1.show()
print("fig"+str(figNum-1)+":",str(psk_order_1)+"PSK时域")
# ---频域1---
# pskFig_fft_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_fft_1=pskFig_1.add_subplot(1,2,2)
pskAx_fft_1=drawFFT(pskAx_fft_1, sampleFreq_2, DMG_2_pskSignal_1, zhFont, fftNumTimes, carrierFreq_2, 2.1 * bytesRate_2, dBAxis, lineWidth,fontSize)
pskAx_fft_1.tick_params(axis="both",labelsize=numberSize)
pskAx_fft_1.yaxis.get_major_formatter().set_powerlimits((0,3))
# pskFig_fft_1.suptitle(str(psk_order_1)+"PSK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    pskFig_1.savefig(workPath+str(figNum-1)+"_"+"pskFig_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    pskFig_1.show()
print("fig"+str(figNum-1)+":",str(psk_order_1)+"PSK频域")
# ---PSK2---
pskFig_2=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域2---
# pskFig_time_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_time_2=pskFig_2.add_subplot(1,2,1)
pskAx_time_2=drawTimeDomain(pskAx_time_2, DMG_1_pskTimeSeries_2, DMG_1_pskSignal_2, zhFont, lineWidth,fontSize)
pskAx_time_2.tick_params(axis="both",labelsize=numberSize)
# pskFig_time_2.suptitle(str(psk_order_2)+"PSK时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     pskFig_time_2.savefig(workPath+str(figNum-1)+"_"+"pskFig_time_2."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     pskFig_time_2.show()
print("fig"+str(figNum-1)+":",str(psk_order_2)+"PSK时域")
# ---频域2---
# pskFig_fft_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_fft_2=pskFig_2.add_subplot(1,2,2)
pskAx_fft_2=drawFFT(pskAx_fft_2, sampleFreq_2, DMG_2_pskSignal_2, zhFont, fftNumTimes, carrierFreq_2, 2.1 * bytesRate_2, dBAxis, lineWidth,fontSize)
pskAx_fft_2.tick_params(axis="both",labelsize=numberSize)
pskAx_fft_2.yaxis.get_major_formatter().set_powerlimits((0,3))
# pskFig_fft_2.suptitle(str(psk_order_2)+"PSK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    pskFig_2.savefig(workPath+str(figNum-1)+"_"+"pskFig_2."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    pskFig_2.show()
print("fig"+str(figNum-1)+":",str(psk_order_2)+"PSK频域")
# ---PSK2---
pskFig_3=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---星座图1---
# pskFig_constel_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_constel_1= axisartist.Subplot(pskFig_3, 1,2,1)#pskFig_constel_1.add_subplot(1,1,1)
pskAx_constel_1=setConstelAxis(pskAx_constel_1,numberSize)
pskAx_constel_1.scatter(DMG_3_pskBand_1_complex.real, DMG_3_pskBand_1_complex.imag,s=markerSize)
pskFig_3.add_axes(pskAx_constel_1)
# pskAx_constel_1.tick_params(axis="both",labelsize=numberSize)
# pskFig_constel_1.suptitle(str(psk_order_1)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     pskFig_constel_1.savefig(workPath+str(figNum-1)+"_"+"pskFig_constel_1."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     pskFig_constel_1.show()
print("fig"+str(figNum-1)+":",str(psk_order_1)+"PSK星座图")
# ---星座图2---
# pskFig_constel_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
pskAx_constel_2=axisartist.Subplot(pskFig_3, 1,2,2)#pskFig_constel_2.add_subplot(1,1,1)
pskAx_constel_2=setConstelAxis(pskAx_constel_2,numberSize)
pskAx_constel_2.scatter(DMG_3_pskBand_2_complex.real, DMG_3_pskBand_2_complex.imag,s=markerSize)
pskFig_3.add_axes(pskAx_constel_2)
# pskAx_constel_2.tick_params(axis="both",labelsize=numberSize)
# pskFig_constel_2.suptitle(str(psk_order_2)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    pskFig_3.savefig(workPath+str(figNum-1)+"_"+"pskFig_3."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    pskFig_3.show()
print("fig"+str(figNum-1)+":",str(psk_order_2)+"PSK星座图")
# --------------QAM--------------
# 绘制：时域、频域、星座图、与psk对比图
# ---QAM1---
qamFig_1=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域1---
# qamFig_time_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_time_1=qamFig_1.add_subplot(1,2,1)
qamAx_time_1=drawTimeDomain(qamAx_time_1, DMG_1_qamTimeSeries_1, DMG_1_qamSignal_1_complex.real, zhFont, lineWidth,fontSize)
qamAx_time_1.tick_params(axis="both",labelsize=numberSize)
# qamFig_time_1.suptitle(str(qam_order_1)+"QAM时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     qamFig_time_1.savefig(workPath+str(figNum-1)+"_"+"qamFig_time_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
# if ifShow:
#     qamFig_time_1.show()
print("fig"+str(figNum-1)+":",str(qam_order_1)+"QAM时域")
# ---频域1---
# qamFig_fft_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_fft_1=qamFig_1.add_subplot(1,2,2)
qamAx_fft_1=drawFFT(qamAx_fft_1, sampleFreq_2, DMG_2_qamSignal_1_complex.real, zhFont, fftNumTimes, carrierFreq_2, 2.1 * bytesRate_2, dBAxis, lineWidth,fontSize)
qamAx_fft_1.tick_params(axis="both",labelsize=numberSize)
qamAx_fft_1.yaxis.get_major_formatter().set_powerlimits((0,3))
# qamFig_fft_1.suptitle(str(qam_order_1)+"QAM频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    qamFig_1.savefig(workPath+str(figNum-1)+"_"+"qamFig_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    qamFig_1.show()
print("fig"+str(figNum-1)+":",str(qam_order_1)+"QAM频域")
# ---QAM2---
qamFig_2=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域2---
# qamFig_time_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_time_2=qamFig_2.add_subplot(1,2,1)
qamAx_time_2=drawTimeDomain(qamAx_time_2, DMG_1_qamTimeSeries_2, DMG_1_qamSignal_2_complex.real, zhFont, lineWidth,fontSize)
qamAx_time_2.tick_params(axis="both",labelsize=numberSize)
# qamFig_time_2.suptitle(str(qam_order_2)+"QAM时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     qamFig_time_2.savefig(workPath+str(figNum-1)+"_"+"qamFig_time_2."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
# if ifShow:
#     qamFig_time_2.show()
print("fig"+str(figNum-1)+":",str(qam_order_2)+"QAM时域")
# ---频域2---
# qamFig_fft_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_fft_2=qamFig_2.add_subplot(1,2,2)
qamAx_fft_2=drawFFT(qamAx_fft_2, sampleFreq_2, DMG_2_qamSignal_2_complex.real, zhFont, fftNumTimes, carrierFreq_2, 2.1 * bytesRate_2, dBAxis, lineWidth,fontSize)
qamAx_fft_2.tick_params(axis="both",labelsize=numberSize)
qamAx_fft_2.yaxis.get_major_formatter().set_powerlimits((0,3))
# qamFig_fft_2.suptitle(str(qam_order_2)+"QAM频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    qamFig_2.savefig(workPath+str(figNum-1)+"_"+"qamFig_2."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    qamFig_2.show()
print("fig"+str(figNum-1)+":",str(qam_order_2)+"QAM频域")
# ---QAM3---
qamFig_3=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---星座图1---
# qamFig_constel_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_constel_1=axisartist.Subplot(qamFig_3, 1,2,1)#qamFig_constel_1.add_subplot(1,1,1)
qamAx_constel_1=setConstelAxis(qamAx_constel_1,numberSize)
qamAx_constel_1.scatter(DMG_3_qamBand_1_complex.real, DMG_3_qamBand_1_complex.imag,s=markerSize)
qamFig_3.add_axes(qamAx_constel_1)
# qamAx_constel_1.tick_params(axis="both",labelsize=numberSize)
# qamFig_constel_1.suptitle(str(qam_order_1)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     qamFig_constel_1.savefig(workPath+str(figNum-1)+"_"+"qamFig_constel_1."+fileType_constel,dpi=saveDPI_constel,format=fileType_constel,bbox_inches='tight',pad_inches=0.0,transparent=True)
# if ifShow:
#     qamFig_constel_1.show()
print("fig"+str(figNum-1)+":",str(qam_order_1)+"QAM星座图")
# ---星座图2---
# qamFig_constel_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
qamAx_constel_2=axisartist.Subplot(qamFig_3, 1,2,2)#qamFig_constel_2.add_subplot(1,1,1)
qamAx_constel_2=setConstelAxis(qamAx_constel_2,numberSize)
qamAx_constel_2.scatter(DMG_3_qamBand_2_complex.real, DMG_3_qamBand_2_complex.imag,s=markerSize)
qamFig_3.add_axes(qamAx_constel_2)
# qamAx_constel_2.tick_params(axis="both",labelsize=numberSize)
# qamFig_constel_2.suptitle(str(qam_order_2)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    qamFig_3.savefig(workPath+str(figNum-1)+"_"+"qamFig_3."+fileType_constel,dpi=saveDPI_constel,format=fileType_constel,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    qamFig_3.show()
print("fig"+str(figNum-1)+":",str(qam_order_2)+"QAM星座图")
# ---对比图1---
contract_qam_psk_fig=plt.figure(figNum, figsize=figSize)
figNum+=1
ax_contract_qam_psk=axisartist.Subplot(contract_qam_psk_fig, 1,1,1)#contract_qam_psk_fig.add_subplot(1,1,1)
ax_contract_qam_psk=setConstelAxis(ax_contract_qam_psk,numberSize)
ax_contract_qam_psk.scatter(DMG_3_pskBand_2_complex.real, DMG_3_pskBand_2_complex.imag,marker="^",s=markerSize)
# ax_contract_qam_psk.set_title(str(psk_order_2)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
ax_contract_qam_psk.scatter(DMG_3_qamBand_2_complex.real, DMG_3_qamBand_2_complex.imag,marker="x",s=markerSize)
# ax_contract_qam_psk.set_title(str(qam_order_2)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
ax_contract_qam_psk.legend([str(psk_order_2)+"PSK星座图",str(qam_order_2)+"QAM星座图"],loc='upper right',prop={"fname":"C:\Windows\Fonts\simsun.ttc","size":fontSize})
contract_qam_psk_fig.add_axes(ax_contract_qam_psk)

# pskAx_constel_contract=axisartist.Subplot(contract_qam_psk_fig, 1,2,1)#pskFig_constel_2.add_subplot(1,1,1)
# pskAx_constel_contract=setConstelAxis(pskAx_constel_contract,numberSize)
# pskAx_constel_contract.scatter(DMG_3_pskBand_2_complex.real, DMG_3_pskBand_2_complex.imag)
# pskAx_constel_contract.set_title(str(psk_order_2)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
# contract_qam_psk_fig.add_axes(pskAx_constel_contract)
#
# qamAx_constel_contract=axisartist.Subplot(contract_qam_psk_fig, 1,2,2)#qamFig_constel_2.add_subplot(1,1,1)
# qamAx_constel_contract=setConstelAxis(qamAx_constel_contract,numberSize)
# qamAx_constel_contract.scatter(DMG_3_qamBand_2_complex.real, DMG_3_qamBand_2_complex.imag)
# qamAx_constel_contract.set_title(str(qam_order_2)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
# contract_qam_psk_fig.add_axes(qamAx_constel_contract)

# ax_contract_qam_psk.tick_params(axis="both",labelsize=numberSize)
# contract_qam_psk_fig.suptitle("QAM和PSK的对比",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    contract_qam_psk_fig.savefig(workPath+str(figNum-1)+"_"+"contract_qam_psk_fig."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    contract_qam_psk_fig.show()
print("fig"+str(figNum-1)+":","QAM和PSK的对比")
# ---对比图2---
contract_qam_psk_fig_2=plt.figure(figNum, figsize=figSize)
figNum+=1
ax_contract_qam_psk_2=axisartist.Subplot(contract_qam_psk_fig_2, 1,1,1)#contract_qam_psk_fig.add_subplot(1,1,1)
ax_contract_qam_psk_2=setConstelAxis(ax_contract_qam_psk_2,numberSize)
ax_contract_qam_psk_2.scatter(DMG_3_pskBand_1_complex.real, DMG_3_pskBand_1_complex.imag,marker="^",s=markerSize)
# ax_contract_qam_psk.set_title(str(psk_order_2)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
ax_contract_qam_psk_2.scatter(DMG_3_qamBand_1_complex.real, DMG_3_qamBand_1_complex.imag,marker="x",s=markerSize)
# ax_contract_qam_psk.set_title(str(qam_order_2)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
ax_contract_qam_psk_2.legend([str(psk_order_1)+"PSK星座图",str(qam_order_1)+"QAM星座图"],loc='upper right',prop={"fname":"C:\Windows\Fonts\simsun.ttc","size":fontSize})
contract_qam_psk_fig_2.add_axes(ax_contract_qam_psk_2)

# pskAx_constel_contract=axisartist.Subplot(contract_qam_psk_fig, 1,2,1)#pskFig_constel_2.add_subplot(1,1,1)
# pskAx_constel_contract=setConstelAxis(pskAx_constel_contract,numberSize)
# pskAx_constel_contract.scatter(DMG_3_pskBand_2_complex.real, DMG_3_pskBand_2_complex.imag)
# pskAx_constel_contract.set_title(str(psk_order_2)+"PSK星座图",fontproperties=zhFont,fontsize=fontSize)
# contract_qam_psk_fig.add_axes(pskAx_constel_contract)
#
# qamAx_constel_contract=axisartist.Subplot(contract_qam_psk_fig, 1,2,2)#qamFig_constel_2.add_subplot(1,1,1)
# qamAx_constel_contract=setConstelAxis(qamAx_constel_contract,numberSize)
# qamAx_constel_contract.scatter(DMG_3_qamBand_2_complex.real, DMG_3_qamBand_2_complex.imag)
# qamAx_constel_contract.set_title(str(qam_order_2)+"QAM星座图",fontproperties=zhFont,fontsize=fontSize)
# contract_qam_psk_fig.add_axes(qamAx_constel_contract)

# ax_contract_qam_psk.tick_params(axis="both",labelsize=numberSize)
# contract_qam_psk_fig_2.suptitle("QAM和PSK的对比",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    contract_qam_psk_fig_2.savefig(workPath+str(figNum-1)+"_"+"contract_qam_psk_fig_2."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    contract_qam_psk_fig_2.show()
print("fig"+str(figNum-1)+":","QAM和PSK的对比_2")
# --------------FSK--------------
# 绘制：时域、频域
# ---FSK1---
fskFig_1=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域1---
# fskFig_time_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
fskAx_time_1=fskFig_1.add_subplot(1,2,1)
fskAx_time_1=drawTimeDomain(fskAx_time_1, DMG_1_fskTimeSeries_1, DMG_1_fskSignal_1, zhFont, lineWidth,fontSize)
fskAx_time_1.tick_params(axis="both",labelsize=numberSize)
# fskFig_time_1.suptitle(str(fsk_order_1)+"FSK时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     fskFig_time_1.savefig(workPath+str(figNum-1)+"_"+"fskFig_time_1."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     fskFig_time_1.show()
print("fig"+str(figNum-1)+":",str(fsk_order_1)+"FSK时域")
# ---频域1---
# fskFig_fft_1=plt.figure(figNum, figsize=figSize)
# figNum+=1
fskAx_fft_1=fskFig_1.add_subplot(1,2,2)
fskAx_fft_1=drawFFT(fskAx_fft_1, sampleFreq_2, DMG_2_fskSignal_1, zhFont, fftNumTimes, carrierFreq_2, 1.8 * (fsk_order_1 - 1) / 2 * seperate_2, dBAxis, lineWidth,fontSize)
fskAx_fft_1.tick_params(axis="both",labelsize=numberSize)
fskAx_fft_1.yaxis.get_major_formatter().set_powerlimits((0,3))
# fskFig_fft_1.suptitle(str(fsk_order_1)+"FSK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    fskFig_1.savefig(workPath+str(figNum-1)+"_"+"fskFig_1."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    fskFig_1.show()
print("fig"+str(figNum-1)+":",str(fsk_order_1)+"FSK频域")
# ---FSK2---
fskFig_2=plt.figure(figNum, figsize=figSize2)
figNum+=1
# ---时域2---
# fskFig_time_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
fskAx_time_2=fskFig_2.add_subplot(1,2,1)
fskAx_time_2=drawTimeDomain(fskAx_time_2, DMG_1_fskTimeSeries_2, DMG_1_fskSignal_2, zhFont, lineWidth,fontSize)
fskAx_time_2.tick_params(axis="both",labelsize=numberSize)
# fskFig_time_2.suptitle(str(fsk_order_2)+"FSK时域",fontproperties=zhFont,fontsize=fontSize)
# if ifSave:
#     fskFig_time_2.savefig(workPath+str(figNum-1)+"_"+"fskFig_time_2."+fileType,dpi=saveDPI,format=fileType)
# if ifShow:
#     fskFig_time_2.show()
print("fig"+str(figNum-1)+":",str(fsk_order_2)+"FSK时域")
# ---频域2---
# fskFig_fft_2=plt.figure(figNum, figsize=figSize)
# figNum+=1
fskAx_fft_2=fskFig_2.add_subplot(1,2,2)
fskAx_fft_2=drawFFT(fskAx_fft_2, sampleFreq_2, DMG_2_fskSignal_2, zhFont, fftNumTimes, carrierFreq_2, 1.8 * (fsk_order_2 - 1) / 2 * seperate_2, dBAxis, lineWidth,fontSize)
fskAx_fft_2.tick_params(axis="both",labelsize=numberSize)
fskAx_fft_2.yaxis.get_major_formatter().set_powerlimits((0,3))
# fskFig_fft_2.suptitle(str(fsk_order_2)+"FSK频域",fontproperties=zhFont,fontsize=fontSize)
if ifSave:
    fskFig_2.savefig(workPath+str(figNum-1)+"_"+"fskFig_2."+fileType,dpi=saveDPI,format=fileType,bbox_inches='tight',pad_inches=0.0,transparent=True)
if ifShow:
    fskFig_2.show()
print("fig"+str(figNum-1)+":",str(fsk_order_2)+"FSK频域")